'use client';
// import { useRouter } from 'next/router';
import { useRouter } from 'next/navigation'; 
import { deleteBlog } from '@/util/actions/blogAction';

const DelectStudentButton = ({ id }) => {
    const router = useRouter(); // 获取 router 实例
//   const removeUserWithId = deleteStudent.bind(null, id);
const removeUserWithId = async () => {
    // await deleteBlog(id);
    try {
        await deleteBlog(id);
        console.log("删除博客成功");
        router.push('/blog'); // 删除成功后重定向到 /blog
      } catch (error) {
        console.error("删除博客时出错:", error);
      }
  };

  const handleSubmit = (e) => {
    e.preventDefault();
    removeUserWithId();
  };

  return (
    <form onSubmit={handleSubmit}>
      {/* <input type='hidden' name='id' value={id} /> */}
      <button type='submit' className='bg-green-400 text-white text-xs rounded p-2'>
        删除
      </button>
    </form>
  );
};

export default DelectStudentButton;